package com.ruoyi.web.controller.cat;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.cat.domain.AdFinance;
import com.ruoyi.cat.service.IAdFinanceService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 金融广告Controller
 * 
 * @author ruoyi
 * @date 2025-05-13
 */
@RestController
@RequestMapping("/system/adFinance")
public class AdFinanceController extends BaseController
{
    @Autowired
    private IAdFinanceService adFinanceService;

    /**
     * 查询金融广告列表
     */
    @PreAuthorize("@ss.hasPermi('system:finance:list')")
    @GetMapping("/list")
    public TableDataInfo list(AdFinance adFinance)
    {
        startPage();
        List<AdFinance> list = adFinanceService.selectAdFinanceList(adFinance);
        return getDataTable(list);
    }

    /**
     * 导出金融广告列表
     */
    @PreAuthorize("@ss.hasPermi('system:finance:export')")
    @Log(title = "金融广告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AdFinance adFinance)
    {
        List<AdFinance> list = adFinanceService.selectAdFinanceList(adFinance);
        ExcelUtil<AdFinance> util = new ExcelUtil<AdFinance>(AdFinance.class);
        util.exportExcel(response, list, "金融广告数据");
    }

    /**
     * 获取金融广告详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:finance:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(adFinanceService.selectAdFinanceById(id));
    }

    /**
     * 新增金融广告
     */
    //@PreAuthorize("@ss.hasPermi('system:finance:add')")
  //  @Log(title = "金融广告", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody AdFinance adFinance)
    {
        AdFinance adFinance1 =   adFinanceService.selectAdFinance();
        if (adFinance1 != null) {
            adFinance.setId(adFinance1.getId());
            adFinanceService.updateAdFinance(adFinance);
        }

        return toAjax(adFinanceService.insertAdFinance(adFinance));
    }

    /**
     * 修改金融广告
     */
    @PreAuthorize("@ss.hasPermi('system:finance:edit')")
    @Log(title = "金融广告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AdFinance adFinance)
    {
        return toAjax(adFinanceService.updateAdFinance(adFinance));
    }


    @GetMapping("reset")
    public AjaxResult remove()
    {
        return toAjax(adFinanceService.deleteAdFinance());
    }

    /**
     * 删除金融广告
     */
    @PreAuthorize("@ss.hasPermi('system:finance:remove')")
    @Log(title = "金融广告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(adFinanceService.deleteAdFinanceByIds(ids));
    }
}
